#! /usr/bin/python3
# _*_ coding:UTF-8 _*_
'''
    名称:装饰器
    作者:王楠
    日期:2020/03/09
    功能:1.0:写装饰器metric 打印出函数执行的时间
'''
import time
import functools


def metric(func):
    @functools.wraps(func)
    def wrapper(*agrs, **kw):
        start = time.time()
        res = func(*agrs, **kw)
        print('%s executed in %f ms' % (func.__name__, (time.time()-start)*1000))
        return res
    return wrapper


@metric
def fast(x, y):
    time.sleep(0.0012)
    return x + y


@metric
def slow(x, y, z):
    time.sleep(0.1234)
    return x * y * z


if __name__ == '__main__':
    f = fast(11, 22)
    s = slow(11, 22, 33)
    if f != 33:
        print('测试失败!')
    elif s != 7986:
        print('测试失败!')
